﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;

namespace CMOCrearSitio
{
    class Program
    {
        static void Main(string[] args)
        {
            CreateSite();
        }

        private static void CreateSite()
        {
            //Crear el contexto do cliente.
            ClientContext clientContext = new ClientContext("http://srvext007:21565");

            //Parâmetros pára o cliente.
            Web oWebSite = clientContext.Web; // >> Crear o novo site dentro do contexto del cliente.
            WebCreationInformation webCreateInfo = new WebCreationInformation(); // >> definição da informação da creação do site.
            webCreateInfo.Title = "Site de Teste";
            webCreateInfo.Description = "Site de equipo";
            webCreateInfo.Url = "SiteProba";
            webCreateInfo.UseSamePermissionsAsParentSite = true; // >> Permissão do site.
            webCreateInfo.WebTemplate = "STS#0"; // >> Tipo de planilha. (Mais info: http://www.sharepointdevwiki.com/display/sp2010/Site+Templates+in+SharePoint+2010).

            Web oNewWebSite = oWebSite.Webs.Add(webCreateInfo);

            clientContext.Load(
                oNewWebSite,
                website => website.ServerRelativeUrl,
                website => website.Created);

            clientContext.ExecuteQuery();

            Console.WriteLine("Server-relative URL: {0} created: {1}", oNewWebSite.ServerRelativeUrl, oNewWebSite.Created);
            Console.ReadLine();
        }
    }
}
